package com.hangwei.paperless.adapter.sub;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseViewHolder;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.BatchStep;
import com.hangwei.paperless.view.SealHelper;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.utils.Tools;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/11/28.
 */

public abstract class BatchStepAdapter extends MyAdapter<BatchStep, BaseViewHolder> {
    public BatchStepAdapter(@Nullable List<BatchStep> data) {
        super(R.layout.item_batch_step, data);
    }


    @Override
    protected void convert(final BaseViewHolder helper, final BatchStep item) {
        helper.setIsRecyclable(false);
//        final TextView qty = helper.getView(R.id.tvQty);
        helper.setText(R.id.tvSeq,Tools.checkedString(item.seq))
                .setText(R.id.tvUnits, Tools.checkedString(item.workUnit))
                .setText(R.id.tvQty1, Tools.checkedString(item.totalQuantity));
        RelativeLayout flUserSeal = helper.getView(R.id.flUserSeal);
        helper.setOnClickListener(R.id.ivReduce, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.totalQuantity>1){
                    item.totalQuantity-=1;
                    helper.setText(R.id.tvQty1,Tools.checkedString(item.totalQuantity));
//                    qty.setText(item.totalQuantity);
                }
            }
        }).setOnClickListener(R.id.ivAdd, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.totalQuantity+=1;
                helper.setText(R.id.tvQty1,Tools.checkedString(item.totalQuantity));
//                qty.setText(item.totalQuantity);
            }
        });
        SealHelper sealHelper = new SealHelper(mContext) {
            @Override
            protected void onSeal() {
                BatchStepAdapter.this.onSeal(item);
            }
        };
        sealHelper.bindData(new SealHelper.SealBean(true, item.technicianStampId, item.technicianId, item.technicianStampTypeCode, item.technicianStampCode, item.technicianDate, item.technician,!TextUtils.isEmpty(item.docroleId)&&item.canSeal));
        flUserSeal.removeAllViews();
        flUserSeal.addView(sealHelper.getItemView());
    }

    protected abstract void onSeal(BatchStep item);

}
